<?php
	include("conn.php");	
	//读取需要编辑的信息到编辑页面
	if(!empty($_GET['id']))	//判断get的值有没有
	{
		$d = $_GET['id'];
		$sql = "select * from news where id = '$d'";
		$query = mysql_query($sql);
		$rs = mysql_fetch_array($query);
	}
	
	//提交
	if(!empty($_POST['sub']))
	{
		$title = $_POST['title'];
		$con = $_POST['con'];
		$hid = $_POST['hid'];
		$sql = "update `news` set title = '$title' , contents = '$con' where id='$hid' limit 1";
		
		mysql_query($sql);
		echo "<script>alert('更新成功！');location.href='index.php'</script>";
	}
?>

<form action="edit.php" method="post">
	标题<input type="text" name="title" value="<?php echo $rs['title']?>"><br>
	<input type="hidden" name="hid" value="<?php echo $rs['id']?>">
	内容<textarea rows="5" cols ="50" name="con"><?php echo $rs['contents']?></textarea><br>

	<input type="submit" name="sub" value="提交编辑">
</form>